package com.shure.surdes.modules.survey.controller;

import com.shure.surdes.common.result.R;
import com.shure.surdes.common.result.Result;
import com.shure.surdes.modules.survey.domain.Answer;
import com.shure.surdes.modules.survey.service.IAnswerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 问卷答案结果Controller
 *
 * @author Shure
 * @date 2021-10-18
 */
@RestController
@RequestMapping("/survey/answer")
public class AnswerController {
    @Autowired
    private IAnswerService answerService;

    /**
     * 查询问卷答案结果列表
     */
    @GetMapping("/list")
    public R list(Answer answer) {
        List<Answer> list = answerService.selectAnswerList(answer);
        return Result.ok(list);
    }

    /**
     * 导出问卷答案结果列表
     */
    @GetMapping("/export")
    public R export(Answer answer) {
        List<Answer> list = answerService.selectAnswerList(answer);
        return Result.ok(list);
    }

    /**
     * 获取问卷答案结果详细信息
     */
    @GetMapping(value = "/{answerId}")
    public R getInfo(@PathVariable("answerId") Long answerId) {
        return Result.success(answerService.selectAnswerByAnswerId(answerId));
    }

    /**
     * 新增问卷答案结果
     */
    @PostMapping
    public R add(@RequestBody Answer answer) {
        return Result.ok(answerService.insertAnswer(answer));
    }

    /**
     * 修改问卷答案结果
     */
    @PutMapping
    public R edit(@RequestBody Answer answer) {
        return Result.ok(answerService.updateAnswer(answer));
    }

    /**
     * 删除问卷答案结果
     */
    @DeleteMapping("/{answerIds}")
    public R remove(@PathVariable Long[] answerIds) {
        return Result.ok(answerService.deleteAnswerByAnswerIds(answerIds));
    }
}
